#include "deepwiki.h"

#include <httpclient.h>

static bool wiki_finish = false;
Deepwiki::Deepwiki()
{

}

QString Deepwiki::name()
{
    return "Deep Wiki(...Bug)";
}

QString Deepwiki::prefix()
{
    return "https://deepwiki.com/";
}

//{
//    "id": "v1.9.9.5/PUBLIC/microsoft/vscode/1b000ef8",
//    "repo_name": "microsoft/vscode",
//    "last_modified": "2025-04-18T04:17:26.052859+00:00",
//    "description": "Visual Studio Code",
//    "stargazers_count": 170101,
//    "language": "TypeScript",
//    "topics": [
//        "editor",
//        "electron",
//        "microsoft",
//        "typescript",
//        "visual-studio-code"
//    ]
//},
QList<QListWidgetItem *> Deepwiki::searching_item(const QString &text)
{
    QList<QListWidgetItem *> list;
    if (!wiki_finish) {
        auto indices = HttpClient::instance().get("https://api.devin.ai/ada/list_public_indexes").toMap().value("indices").toList();
        foreach (auto var, indices) {
            auto indice = var.toMap();
            auto id = indice.value("id").toString();
            auto repo_name = indice.value("repo_name").toString();
            auto last_modifie = indice.value("last_modified").toString();
            auto description = indice.value("description").toString();
            auto stargazers_count = indice.value("stargazers_count").toString();
            auto language = indice.value("language").toString();
            auto topics = indice.value("topics").toString();

            auto item = newItem();
            item->setText(repo_name);
            list.append(item);
        }
        wiki_finish = true;
    }
    return list;
}

QString Deepwiki::content_item(const QListWidgetItem *item)
{
    return prefix() + item->text();
}
